package com.huluobo.a2112mvvmdouyindemo.live;

import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.huluobo.mvvm_base.bean.FollowBeanResult;
import com.huluobo.mvvm_base.bean.GiftBeanResult;
import com.huluobo.mvvm_base.bean.Money;
import com.huluobo.mvvm_base.net.Const;
import com.huluobo.mvvm_base.viewmodel.BaseViewModel;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

/**
 * Created by LC on 2024/4/1.
 */
public class LiveViewModel extends BaseViewModel<LiveRepo> {

    MutableLiveData<FollowBeanResult> followSuccess = new MutableLiveData<>();

    MutableLiveData<String> followFailed = new MutableLiveData<>();

    MutableLiveData<FollowBeanResult> noFollowSuccess = new MutableLiveData<>();

    MutableLiveData<String> noFollowFailed = new MutableLiveData<>();

    MutableLiveData<GiftBeanResult> getGiftListSuccess = new MutableLiveData<>();
    MutableLiveData<String> getGiftListFailed = new MutableLiveData<>();

    MutableLiveData<Money> queryMoneySuccess = new MutableLiveData<>();

    MutableLiveData<String> queryMoneyFailed = new MutableLiveData<>();

    public void updateUserMoney(Money money) {
        repo.updateUserMoney(money);
    }

    public void queryMoney(String username) {
        repo.queryUserMoney(username, queryMoneySuccess, queryMoneyFailed);
    }

    public void getGiftList() {
        repo.getGiftList(getGiftListSuccess, getGiftListFailed);
    }

    public void followAuth(String authName) {
        Map<String, String> map = new HashMap<>();
        map.put(Const.PARAM_AUTHNAME, authName);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.MEDIA_PARSE), json);
        repo.follow(body, followSuccess, followFailed);
    }

    public void noFollowAuth(String authName) {
        Map<String, String> map = new HashMap<>();
        map.put(Const.PARAM_AUTHNAME, authName);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.MEDIA_PARSE), json);
        repo.noFollowAuth(body, noFollowSuccess, noFollowFailed);
    }

    @Override
    protected LiveRepo createRepo() {
        return new LiveRepo();
    }
}
